package com.jy.adscm.zltx.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.zltx.bean.SjFileTrain;
import com.jy.adscm.zltx.mapper.mysql.SjFileTrainMapper;
import com.jy.adscm.zltx.service.SjFileTrainService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-11-08
 */
@Service
public class SjFileTrainServiceImpl extends ServiceImpl<SjFileTrainMapper, SjFileTrain> implements SjFileTrainService {
     @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public List<SjFileTrain> selectByFileId(Integer fileId) throws AdscmSystemException {
        Wrapper<SjFileTrain> wrapper =new EntityWrapper<>();
        wrapper.eq("fileId",fileId);
        List<SjFileTrain> sjFileTrains = super.selectList(wrapper);
        for (SjFileTrain sjFileTrain : sjFileTrains) {
            if (sjFileTrain.getTrainer()!=null&& !"".equals(sjFileTrain.getTrainer())){
                JyUser jyUser = jyUserMapper.selectById(sjFileTrain.getTrainer());
                sjFileTrain.setTrainerName(jyUser.getName());
            }
        }

        return sjFileTrains;
    }
}
